Skip to content

Harden IPFS uploads and enforce strict Zod validation - #1438

Open
CillaSam wants to merge 2 commits into
Akanimoh12:test-implement-dripsfrom
CillaSam:fix/1232-1233-ipfs-upload-and-zod-strict-validation
Open

Harden IPFS uploads and enforce strict Zod validation#1438
CillaSam wants to merge 2 commits into
Akanimoh12:test-implement-dripsfrom
CillaSam:fix/1232-1233-ipfs-upload-and-zod-strict-validation

Conversation

@CillaSam

Copy link
Copy Markdown

Summary

  • Validate and sanitize IPFS upload content #1232 — Validate and sanitize IPFS upload content. Uploaded images are now verified by their actually-decoded content (via sharp/libvips format detection) instead of the client-supplied MIME type or filename extension. Only a fixed raster allowlist (jpeg/png/gif/webp) is accepted — SVG is rejected outright since it can carry scripts. Accepted images are bounded to 4096×4096px and re-encoded before pinning, which strips all EXIF/IPTC/XMP metadata (including GPS) and drops any bytes outside the actual image data (defense against polyglot files).
  • Add strict validation to all Zod schemas #1233 — Add strict validation to all Zod schemas. Every schema that parses a mutating endpoint's request body (plus IPFS's CID param schema) now calls .strict(), so unrecognized fields are rejected with a 400 naming the offending key. Also fixed two mass-assignment gaps found while auditing Prisma writes that spread parsed input directly: notifications.service.ts and moderation.service.ts now use explicit field allowlists, and the previously-unvalidated POST /admin/audit-log body now goes through its schema.

Test plan

  • backend/src/modules/ipfs/ipfs.test.ts — valid image, spoofed content-type, SVG rejection, oversized dimensions, EXIF/GPS stripping, HTTP route integration (26 tests)
  • backend/tests/zodStrictValidation.test.ts — every mutating-endpoint body schema (plus the IPFS CID param schema) accepts its valid payload and rejects an unrecognized field (79 tests)
  • npm test across affected modules — no regressions (failures seen locally are pre-existing and require a live Postgres/Redis not available in this sandbox)
  • npm run typecheck — no new errors introduced
  • npm run lint — clean on all changed files

Closes #1232, Closes #1233

Uploaded images are now verified by their actual decoded content
(via sharp/libvips format detection) instead of the client-supplied
MIME type or filename extension, which are both attacker-controlled.
Only a fixed raster allowlist (jpeg/png/gif/webp) is accepted; SVG is
rejected outright since it can carry scripts and can't be verified
the same way. Accepted images are bounded to 4096x4096px and re-encoded
before pinning, which strips all EXIF/IPTC/XMP metadata (including GPS)
and drops any bytes outside the actual image data — closing off the
classic polyglot-file trick of appending a payload after a format's
end-of-data marker.

Tests cover a valid image, a spoofed content-type, SVG rejection,
oversized dimensions, and EXIF/GPS stripping.
…kanimoh12#1233)

Every schema that parses a mutating endpoint's request body (plus
IPFS's CID param schema) now calls .strict(), so an unrecognized field
is rejected with a 400 naming the offending key instead of silently
passing through — the existing global error handler already surfaces
Zod's unrecognized-key message via the VALIDATION_ERROR response.

Also closes two mass-assignment gaps found while auditing Prisma
writes for spread input:
- notifications.service.ts upserted a preference row with
  `{ userId, ...patch }` / `patch`; now lists each column explicitly.
- moderation.service.ts spread the full report input into an audit
  log's metadata field; now lists each field explicitly.
- admin's POST /admin/audit-log read action/target/metadata straight
  off req.body with no validation at all; it now parses through
  createAuditLogSchema first.

Added tests/zodStrictValidation.test.ts, which exercises every one of
these schemas against its minimal valid payload plus one with an
unrecognized field, so every mutating endpoint's schema is covered by
a rejection test in one place.
@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@CillaSam Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add strict validation to all Zod schemas Validate and sanitize IPFS upload content

1 participant